﻿<%@ control language="C#" autoeventwireup="true" inherits="UserControl_ManagerGroupProduct, App_Web_pmcgjoc4" %>
<%@ Import Namespace="DacSanMienTayOBJ" %>

<%@ Import Namespace="System.Collections.Generic" %>
<script type="text/javascript" src="Scripts/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="<%=Utility.modHost %>/Scripts/jquery.simplemodal.js"></script>

<style>
#simplemodal-overlay {background-color:#000;}
#simplemodal-container {height:378px; width:619px; color:#bbb; background:url(../Images/bg_login.png) no-repeat center; padding:12px; position:relative;}
#simplemodal-container .simplemodal-data {position:relative;}
#simplemodal-container a.modalCloseImg {background:url(../Images/x.png) no-repeat; width:25px; height:29px; display:inline; z-index:3200; position:absolute; top:0px; right:0px; cursor:pointer;}

#simplemodal_container_uploadimage {height:490px; width:700px; color:#bbb;background-color:White;border:5px;border-style:solid;border-color:#ce5c00; position:relative;margin-top:50px}
#simplemodal_container_uploadimage .simplemodal-data {position:relative;}
#simplemodal_container_uploadimage a.modalCloseImg {background:url(../Images/x.png) no-repeat; width:25px; height:29px; display:inline; z-index:3200; position:absolute; top:-16px; right:-16px; cursor:pointer;}

</style>

<div>
<span>
Tên group
</span>
<input type="text" style="width:300px;left:16px; position:relative" id="txtGroupName" name="txtGroupName">
<br />
<br />
<span>Từ khóa</span>
<textarea id="txtKeyword" style="width:300px;left:30px; position:relative" name="txtKeyword" rows="3" cols="1"></textarea>
<br />
<asp:Button ID="cmdInsert" runat="server" Text="Thêm mới" 
    OnClientClick="return CheckRegullar()" />

</div>
<br />
<br />

<div>
<span>
Danh Sách nhóm sản phẩm 

</span>
<br />
<br />
<table>
<tr>
<td style="width:60px">Mã nhóm</td>
<td style="width:200px">Tên nhóm</td>
<td style="width:360px">Từ khóa</td>
<td style="width:100px">Tình trạng</td>
<td style="width:100px">Cập nhật</td>
<td style="width:100px">Lock/Unlock</td>
</tr>

<tbody id="bodyGroupProduct">
<%
    try
    {
        List<GroupProduct> list = GroupProductBusiness.ListAllGroupProduct(ConnectionType.AdminConnection);
        if (list != null)
        {
            int vt = 0;
            foreach (GroupProduct group in list)
            {
                string status = "";
                if (group.IsVisible == 1)
                {
                    status = "Active";
                }
                else
                {
                    status = "Inactive";
                }

                
     %>
<tr id="trVtGroup<%=vt %>">
    <td><label id="lbGroupID<%=vt %>" title="<%=group.GroupID %>"><%=group.GroupID%></label></td>
    <td><input type="text" style="width:350px" value="<%=group.GroupName %>" id="txtName<%=vt %>" /> </td>
    <td><textarea type="text" style="width:350px" id="txtKeywordUpdate<%=vt %>" cols="1" rows="2" ><%=group.MetaKeyword %></textarea> </td>
    <td><%=status %></td>
    <td><input type="button" value="Cập nhật" onclick="UpdateGroupProduct('<%=group.GroupID %>','<%=vt %>','<%=group.IsVisible %>')" /> </td>
    <td>
    <%
        if (group.IsVisible == 1)
        {
        %>
            <input type="button" value="Lock" onclick="LockAndUnclockGroupProduct('<%=group.GroupID %>','<%=vt %>','lock','<%=group.IsVisible %>')" />
            <%
        }
        else
        {
        %>
            <input type="button" value="UnLock" onclick="LockAndUnclockGroupProduct('<%=group.GroupID %>','<%=vt %>','unlock','<%=group.IsVisible %>')" />
            <%
        }
                 %>
                 </td>
                 
</tr>

<%
    vt++;
    }
        }
    }
    catch(Exception ex)
    {
        Utilitys.WriteLog(ex.Message);
    }
     %>
</tbody>
</table>
</div>
<script type="text/javascript">

    function CheckRegullar() {
        var groupName = $('#txtGroupName').val();
        if (groupName == '') {
            alert('Vui lòng nhập tên nhóm');
            return false;

        }
        else {
            return true;
        }
    }

    function UpdateGroupProduct(groupID, vt, visible) {
        var txtName = '#txtName' + vt;
        var trGroupID = "#trVtGroup" + vt;
        var groupName = $(txtName).val();

        var txtKeyword = '#txtKeywordUpdate' + vt;
        var keyword = $(txtKeyword).val();

//        var lbGroupID = '#lbGroupID' + vt;
//        var groupID = $(lbGroupID).text();
        var load = '<img src="<%=Utility.modHost %>/Images/loading.gif" id="imgLoad" alt="" style="margin-left:auto;margin-right:auto;margin-top:53%;margin-left:135%;width:40px;height:40px" />';
        $(trGroupID).html(load);
        $.ajax({
            type: "post",
            url: "<%=Utility.modHost %>/Proccess/UpdateAllFieldGroupProduct.aspx",
            async: false,
            data: { groupID: groupID, groupName: groupName,keyword:keyword, vt: vt, visible: visible },
            success: function (data2) {
                if (data2 == "errorupdategroup") {
                    alert('Lỗi cập nhật. Vui lòng liên hệ admin');
                }
                else {
                    document.getElementById('trVtGroup' + vt).innerHTML = data2;
                }
            }
        });

    }

    function LockAndUnclockGroupProduct(groupID, vt, typeLock, visible) {
        var txtName = '#txtName' + vt;
        var trGroupID = "#trVtGroup" + vt;
        var groupName = $(txtName).val();

        var txtKeyword = '#txtKeywordUpdate' + vt;
        var keyword = $(txtKeyword).val();
        var load = '<img src="<%=Utility.modHost %>/Images/loading.gif" id="imgLoad" alt="" style="margin-left:auto;margin-right:auto;margin-top:53%;margin-left:135%;width:40px;height:40px" />';
        $(trGroupID).html(load);
        $.ajax({
            type: "post",
            url: "<%=Utility.modHost %>/Proccess/LockAndUnclockGroupProduct.aspx",
            async: false,
            data: { groupID: groupID, typeLock: typeLock, vt: vt, visible: visible, groupName: groupName, keyword: keyword },
            success: function (data2) {
                if (data2 == "errorlock") {
                    alert('Không khóa được. Vui lòng liên hệ admin');
                }
                else if (data2 == "errorunlock") {
                    alert('Không mở khóa được. Vui lòng liên hệ admin');
                }
                else {
                    document.getElementById('trVtGroup' + vt).innerHTML = data2;
                }
            }
        });
    }
</script>